fix(readme): make the README code samples compile - #577
Merged
Conversation
The "Usage with a client" snippet assigned a string literal to clerk.ClientConfig.Key, which is a *string. Fixing that surfaced more compile errors across the README's Go snippets, so every snippet was audited and verified by extracting them into a scaffold module and running go build and go vet against the SDK at HEAD. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
mauricioabreu
approved these changes
Jul 7, 2026
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to https://github.com/clerk/clerk/pull/2891, which fixed the same issues on the Go quickstart docs page and flagged this README as having the same
config.Key = "sk_live_XXX"bug.clerk.ClientConfigembedsBackendConfig, whoseKeyfield is a*string, so the snippet didn't compile. Auditing the rest of the README's Go snippets turned up several more compile errors, fixed here as well.Changes
config.Key = "sk_live_XXX"→config.Key = clerk.String("sk_live_XXX")(Keyis a*string).$resource$usage templates: repeatedresource, err := ...redeclarations →=for Get/Update; Delete now usesdeletedResource, err :=sinceDeletereturns*clerk.DeletedResource, not the resource type.contextandfmtimports;organizationmembership.List(ctx, params)passed an undefined variable →&listParams;ListParams.OrganizationIDis required (it builds the/organizations/{id}/membershipspath) and is now set toorg.ID;memberships.TotalCount < 0can never be true →== 0;memberships[0]indexed a struct →memberships.OrganizationMemberships[0];membership.UserIDdoesn't exist →membership.PublicUserData.UserID; added error handling and a finalfmt.Println(usr.ID)soerrandusrare no longer declared-and-not-used.dmn.Response.TraceID,apiErr.TraceID,apiErr.Response.RawJSON) are "evaluated but not used" compile errors → printed withfmt.Println.func (r *mockRoundTripper) RoundTrip(r *http.Request)reusedrfor receiver and parameter (duplicate argument) → receiver renamed tom; stub bodies were missingreturnstatements → minimal returns added; the last custom backend tookreader *clerk.ResponseReader(pointer to interface, doesn't satisfyclerk.Backend) →clerk.ResponseReader; the two client-based tests declaredclientwithout using it → aclient.Getcall added.The two
$resource$usage blocks stay illustrative fragments by design — beyond the$resource$placeholder they hold top-level statements (ctx := ...,clerk.SetKey(...)) that aren't valid at Go file scope, so they don't compile standalone even with a real resource substituted. They teach the CRUD shape; the reader drops them into a function and uses the results (the// do something with the resourcecomment marks that). The complete, compile-clean runnable example immediately follows them. This PR removes their genuine compile bugs (the:=redeclarations and the wrongDeletereturn binding) without turning the concise shape illustrations into full programs.Verification
All 13
gofences were extracted from the edited README into a scaffold module (each snippet in its own package, fragments wrapped with the minimalpackage/funcboilerplate a reader would supply,$resource$substituted withuser) requiringgithub.com/clerk/clerk-sdk-go/v2at this branch's HEAD.go build ./...andgo vet ./...both pass. As a negative control, the same harness against the unedited README produces 20 compile-error lines.References
🤖 Generated with Claude Code